// 引入 axios
import request from '@/utils/request'

/**
 *获取用户登录的账号密码
 * @param Promise对象
 * {*} param0 电话号和验证码
 */
export const LoginApi = ({ mobile, code }) => request({
  url: '/v1_0/authorizations',
  method: 'POST',
  data: {
    mobile,
    code
  }

})

/**
 *获取所有频道列表
 */
export const getChannelListAPI = () => request({
  url: '/v1_0/channels'
})

/**
 *获取用户选择频道列表数据
 */
export const getChannelsApi = () => request(
  {
    url: '/v1_0/user/channels'
  })

// 用户添加频道列表
export const getUserAddChannelApi = (channelsArr) => request({
  url: '/v1_0/user/channels',
  method: 'PUT',
  data: {
    channels: channelsArr
  }
})

// 删除用户选择频道
export const getUserDelChannelApi = (channelId) => request({
  url: `/v1_0/user/channels/${channelId}`,
  method: 'DELETE',
  headers: {
    'Content-Type': 'application/x-www-form-urlencoded'
  }
})

/**
   *获取文章列表
   * @param {*}
   * channel_id
   */
export const articlesListApi = ({ channel_id, timestamp = new Date() }) => request({
  url: '/v1_0/articles',
  params: {
    channel_id,
    timestamp
  }
})

// 对文章的不喜欢
export const disLikeApi = (artId) => request({
  url: '/v1_0/article/dislikes',
  method: 'POST',
  data: { target: artId }
})

// 举报文章
export const reportsArticleApi = ({ target, type }) => request({
  url: '/v1_0/article/reports',
  method: 'POST',
  data: {
    target,
    type,
    remark: '其他问题'
  }
})

// 文章搜索结果页
export const searchResultApi = ({
  page = 1,
  per_page = 10,
  // 关键字 keyWords
  keyWords
}) => request({
  url: '/v1_0/search',
  params: {
    page,
    per_page,
    q: keyWords
  }
})

// 获取联想建议
export const getSearchSuggestionApi = (inputVal) => request({
  url: '/v1_0/suggestion',
  params: {
    q: inputVal
  }
})
// 文章详情页
export const getArticlesDetail = ({ artId }) => request({
  url: `/v1_0/articles/${artId}`
})

// 文章 用户关注
export const followUserApi = (authorId) => request({
  url: '/v1_0/user/followings',
  method: 'POST',
  data: {
    target: authorId
  }
})

// 文章用户取消关注
export const unfollowUserApi = (authorId) => request({
  url: `/v1_0/user/followings/${authorId}`,
  method: 'DELETE'
})

// 对文章的点赞
export const likeArticlesApi = (artId) => request({
  url: '/v1_0/article/likings',
  method: 'POST',
  data: {
    target: artId
  }
})
// 取消文章的点赞
export const unLikeArticlesApi = (artId) => request({
  url: `/v1_0/article/likings/${artId}`,
  method: 'DELETE'
})

// 文章的评论点赞
export const getCommentsApi = ({ artId, offset = null, limit = 10 }) => request({
  url: '/v1_0/comments',
  params: {
    type: 'a',
    source: artId,
    offset,
    limit
  }
})

// 对评论回复的点赞
export const likeCommentApi = (commentId) => request({
  url: '/v1_0/comment/likings',
  method: 'POST',
  data: {
    target: commentId
  }
})

// 取消评论回复的点赞
export const unLikeCommentApi = (commentId) => request({
  url: `/v1_0/comment/likings/${commentId}`,
  method: 'DELETE'
})

// 对文章评论
export const publishCommentApi = ({ target, content, artId = null }) => {
  const obj = {
    target: target,
    content: content
  }
  // 如果artId为空说明对文章进行评论
  // 如果传参说明对评论进行评论
  if (artId !== null) {
    obj.art_id = artId
  }
  return request({
    url: '/v1_0/comments',
    method: 'POST',
    data: obj
  })
}

// 我的页面->获取用户信息
export const getUserInfoApi = () => request({
  url: '/v1_0/user'
})

// 编辑用户信息 带birthday参数
export const userEditApi = () => request({
  url: '/v1_0/user/profile'
})

// 编辑用户资料
export const userHerderImgApi = (fd) => request({
  url: '/v1_0/user/photo',
  method: 'PATCH',
  data: fd
})
